package com.jiangli.utils;

import org.apache.commons.lang.RandomStringUtils;
import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;
import java.util.Random;

public class PasswordEncoder {

    public static String encode(String password) {
        // 生成盐
        String salt = RandomStringUtils.random(20);
        // 加密
        return encode(password,salt);
    }
    private static String encode(String password, String salt) {
        // 加密
        return salt + "@" + DigestUtils.md5DigestAsHex((password + salt).getBytes(StandardCharsets.UTF_8));
    }

}
